Bad Design? Constructor of composition uses `this`
Posted
by tanascius
on Stack Overflow
See other posts from Stack Overflow
or by tanascius
Published on 2010-04-09T15:53:51Z
Indexed on
2010/04/11
7:03 UTC
Read the original article
Hit count: 216
Example:
class MyClass
{
Composition m_Composition;
void MyClass()
{
m_Composition = new Composition( this );
}
}
I am interested in using depenency-injection here. So I will have to refactor the constructor to something like:
void MyClass( Composition composition )
{
m_Composition = composition;
}
However I get a problem now, since the Composition
-object relies on the object of type MyClass
which is just created.
Can a dependency container resolve this? Is it supposed to do so?
Or is it just bad design from the beginning on?
© Stack Overflow or respective owner